<?php
/**
 * 客户拜访模型
 */
class visitModel extends RelationModel {
	
    //发起关联，给后台使用，前台API 不需要使用这个
    protected $_link = array(
        'user' => array(
            'mapping_type' => BELONGS_TO,
            'class_name' => 'admin',
            'foreign_key' => 'userId',
            'as_fields'=>'userName,realName',
        ),
        'store' => array(
            'mapping_type' => BELONGS_TO,
            'class_name' => 'store',
            'foreign_key' => 'storeId',
            'as_fields'=>'name,ctms,channel,regionId',
        ),  
    );  
        
    public function setStoreLinkCondition($str){
        $this->_link['store']['condition'] = $str;
    }    
        
	/**
	 * 获得巡检表表单字段
	 */
	public function getFormField($modular , $visitId = 0) {
		$res = array();
		$parent = D('attribute')->where(array('modular'=>$modular, 'pid'=>0))->find();
		$attribute = D('attribute')->where(array('pid'=>$parent['id']))->select();
		foreach($attribute as $row){
			if($visitId){
				$val = D('attributevar')->where(array('pid'=>$visitId ,'optionid'=>$row['id']))->find();
			}
			
			$row['value'] = isset($val['value']) ? $val['value'] : '';
			
			$res[] = $row;
		}
		return $res;
	}

}

/* End of file visitModel.class.php */